<?php
/**
 * Created by PhpStorm.
 * User: fengzi
 * Date: 2019/5/29
 * Time: 17:18
 */

namespace app\vehicle\model;
use think\Model;

class CouponUser extends Model{
    public function coupon(){
        return $this->hasOne('coupon','id','coupon_id')->bind('title');
    }

    public function getStatusAttr($value){
        $arr = ['未使用','已使用','已过期'];
        return $arr[$value];
    }

    public function getStartTimeAttr($value){
        return date('Y-m-d',$value);
    }

    public function getendTimeAttr($value){
        return date('Y-m-d',$value);
    }

    public function getuseTimeAttr($value){
        if($value) {
            return date('Y-m-d', $value);
        }else{
            return;
        }
    }

    public function user(){
        return $this->hasOne('user','id','user_id')->bind([
            'nick_name'=>'nick_name',
            'head_pic'=>'head_pic'
        ]);
    }
}